< Back

Document Subject: Display Latest 5 Documents
Hint Short Cut: Add this to your code & documentation to help you find this page.
http://#Display Latest Documents or http://A555F9/nn.nsf/ByAlias/Display Latest Documents

How do you display the latest 5 documents on a web page? Here is the complete code and explanation.




To display the last few documents created or modified on a web page is not as trivial as first thought.

 

The easiest way is to create a view LastDocs with date as the first column and then sort it descending.

To display the view with only the first (or last) 5 documents showing can be done using the ?openview&count=5  code

on the end of a view.

 

The view can be  displayed in an Iframe if you are not worried about search engines.

REM {Displays last 5 Release document by issue date};
DBName := @Implode(@Explode(@Subset(@DbName;-1); @Char(92));"/");
url:="/"+DBName+"/LastDocs?openview&count=5"
"<IFRAME height=100 width=712 scrolling=no frameborder=0 marginwidth=0 marginheight=0  src='"+url+"'>"+
"<a href='"+url+"'>here</a>"+
"</IFRAME>"

To be really cool, automatically change the size of the iframe to fit the content by going here: http://www.notesninjas.com/A555F9/nn.nsf/ByAlias/IframeHeight .

Might be best to create a $$ViewTemplate for LastDocs form that has the Head Head COntent set to:

"<base target='_top' >"

This will make sure the links replace the current page and do not open in the iframe!

If you do not want to use the Iframe, then there are other options, create a function that does a @dbcolumn and a @subset, this could be tricky and slow on a big view, or create an agent that creates javascript on the fly like a google adsense script. I will create an article on this at a later date.